//
//  HYHomeTableViewCell.m
//  Booking
//
//  Created by Duntech on 2018/4/19.
//  Copyright © 2018年 Duntech. All rights reserved.
//

#import "HYHomeTableViewCell.h"

@implementation HYHomeTableViewCellModel

@end

@implementation HYHomeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = KAPP_WHITE_COLOR;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.bgImgView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.arrowImgView];
    }
    return self;
}

- (void)layoutSubviews{
    
    [_bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(20 * WIDTH_MULTIPLE);
        make.bottom.equalTo(self.contentView).offset(-20 * WIDTH_MULTIPLE);
    }];
    
    [_arrowImgView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView).offset(-20 * WIDTH_MULTIPLE);
    }];
}

- (void)configWithModel:(HYBaseCellModel *)model{
    
    HYHomeTableViewCellModel *cellModel = (HYHomeTableViewCellModel *)model;
    self.titleLabel.text = cellModel.title;
    self.bgImgView.image = [UIImage imageNamed:cellModel.backgroundImageName];
}

#pragma mark - lazyload
- (UIImageView *)bgImgView{
    
    if (!_bgImgView) {
        
        _bgImgView = [UIImageView new];
        _bgImgView.contentMode = UIViewContentModeScaleAspectFill;
        _bgImgView.clipsToBounds = YES;
        _bgImgView.image = [UIImage imageNamed:@"image_placeholder"];
    }
    return _bgImgView;
}

- (UILabel *)titleLabel{
    
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.font = KFitBoldFont(18);
        _titleLabel.numberOfLines = 0;
        _titleLabel.textColor = KAPP_WHITE_COLOR;
    }
    return _titleLabel;
}

- (UIImageView *)arrowImgView{
    
    if (!_arrowImgView) {
        _arrowImgView = [UIImageView new];
        _arrowImgView.image = [UIImage imageNamed:@"home_arrow"];
    }
    return _arrowImgView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
